#include "zhu.h"
#include "base1.h"

zhu::zhu()
{
    //初始化加载飞机图片资源
    m_plane.load(ZHU_PALNE);

    //初始化飞机坐标
    m_x=(GAME_WIDTH-m_plane.width())*0.5;
    m_y=GAME_HEIGHT-m_plane.height();

    //初始化矩形边框
    m_Rect.setWidth(m_plane.width());
    m_Rect.setHeight(m_plane.height());
    m_Rect.moveTo(m_x,m_y);

    //初始化时间间隔
    m_recorder=0;
}
void zhu::setPosition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_Rect.moveTo(m_x,m_y);
}

void zhu::shoot()
{
    //累加时间间隔记录
    m_recorder++;

    //如果记录的数字，未达到发射子弹的时间间隔，直接return，不发射子弹
    if(m_recorder<BULLET_INTERVAL)
    {
        return;
    }
    //到达发射时间
    m_recorder=0;

    //发射子弹
    for(int i=0;i<BULLET_NUM;i++)
    {
        //如果是空闲的子弹，进行发射
        if(m_bullets[i].m_free)
        {
            //先将空闲状态改为假
            m_bullets[i].m_free=false;
            //设置子弹坐标
            m_bullets[i].m_x=m_x+54;
            m_bullets[i].m_y=m_y;
            break;
        }


    }
}

